﻿package mortal.game.view.wizard.newPanel
{
    import Message.Public.*;
    import __AS3__.vec.*;
    import com.greensock.*;
    import com.greensock.easing.*;
    import com.mui.controls.*;
    import com.mui.utils.*;
    import extend.language.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.component.ui.*;
    import mortal.game.events.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.wizard.data.*;
    import mortal.game.view.wizard.panel.*;
    import mortal.mvc.core.*;

    public class WizardRightPart extends GSprite
    {
        private var _soulBg:GImageBitmap;
        private var _upgradeBtn:GLoadingButton;
        private var _consumeBox:GConsumeBox;
        private var _consumeBox2:GConsumeBox;
        private var _attrSprite:GSprite;
        private var _soulPanel:WizardSoulPanel;
        private var _comBat:BitmapNumberText;
        private var _level:GTextFiled;
        private var _name:GImageBitmap;
        private var _addCombat:GTextFiled;
        private var _addCombatIcon:GBitmap;
        private var _vcAttributeName2:Vector.<String>;
        private var _vcAttributeValueText:Vector.<BitmapNumberText>;
        private var _vcAttributeAddValueText:Vector.<GTextFiled>;
        private var _vcAttributeAddValueBitMap:Vector.<GBitmap>;
        private var _currentWizardData:WizardData;
        private var _isOver:Boolean = false;

        public function WizardRightPart()
        {
            this._vcAttributeName2 = new Vector.<String>;
            this._vcAttributeValueText = new Vector.<BitmapNumberText>;
            this._vcAttributeAddValueText = new Vector.<GTextFiled>;
            this._vcAttributeAddValueBitMap = new Vector.<GBitmap>;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            var _loc_3:GTextFiled = null;
            var _loc_4:BitmapNumberText = null;
            var _loc_5:GBitmap = null;
            var _loc_7:int = 0;
            super.createDisposedChildrenImpl();
            this._soulBg = UIFactory.gImageBitmap(ImagesConst.WizardTotalAttrBg, 0, 0, this);
            var _loc_1:* = GlobalStyle.textFormatLv.left();
            _loc_1.size = 20;
            this._level = UIFactory.gTextField("", 5, 3, 80, 35, this, _loc_1);
            this._upgradeBtn = UIFactory.gLoadingButton(ResFileConst.WizardUpgrade, 73, 468, 110, 33, this);
            this._upgradeBtn.name = "Wizard_UpgradeBtn";
            this._upgradeBtn.drawNow();
            this._upgradeBtn.configEventListener(MouseEvent.CLICK, this.upgradeHandler);
            this._upgradeBtn.configEventListener(MouseEvent.MOUSE_OVER, this.showAttrUp);
            this._upgradeBtn.configEventListener(MouseEvent.MOUSE_OUT, this.hidAttrUp);
            this._consumeBox = UIFactory.gConsumeBox("", -10, 500, 0, this);
            this._consumeBox.addItem(ConsumeData.UseMoneyType, EPriceUnit._EPriceUnitVitalEnergy, 0, Language.getString(30409), "2");
            this._consumeBox.addItem(ConsumeData.UseMoneyType, EPriceUnit._EPriceUnitCoinBind, 0, Language.getString(30408), "1");
            this._consumeBox2 = UIFactory.gConsumeBox("", -10, 521, 0, this);
            this._consumeBox2.addItem(ConsumeData.ShowMoneyType, EPriceUnit._EPriceUnitVitalEnergy, 0, Language.getString(30410), "3");
            this._soulPanel = UICompomentPool.getUICompoment(WizardSoulPanel);
            this._soulPanel.x = -194;
            this._soulPanel.y = 240;
            this.addChild(this._soulPanel);
            this._comBat = UIFactory.bitmapNumberText(131, 77, "WizardCombatNum.png", 23, 30, -3, this, 13, BitmapNumberText.Mid);
            this._comBat.text = "0";
            this._name = UIFactory.gImageBitmap("", 55, -5, this);
            _loc_1 = GlobalStyle.textFormatItemGreen.left();
            _loc_1.size = 16;
            this._addCombat = UIFactory.gTextField("", 205, 77, 60, 25, this, _loc_1);
            this._addCombatIcon = UIFactory.gBitmap(ImagesConst.ascendingSortBtn_upSkin, 195, 83, this);
            this._addCombatIcon.visible = false;
            this._attrSprite = UICompomentPool.getUICompoment(GSprite);
            this._attrSprite.x = 19;
            this._attrSprite.y = 140;
            this._attrSprite.name = "wizard_SoulPanel";
            this.addChild(this._attrSprite);
            this.addChild(this._upgradeBtn);
            this._vcAttributeName2.length = 0;
            this._vcAttributeValueText.length = 0;
            this._vcAttributeAddValueText.length = 0;
            this._vcAttributeAddValueBitMap.length = 0;
            var _loc_2:* = WizardConfig.instance.vcAttributeName;
            var _loc_6:* = GlobalStyle.textFormatAnHuan;
            _loc_6.size = 12;
            while (_loc_7 < _loc_2.length)
            {
                
                _loc_4 = UIFactory.bitmapNumberText(32 + _loc_7 % 2 * 130, 8.5 * (_loc_7 - _loc_7 % 2) + 24, "RoleInfoNum.png", 8, 10, -1, this._attrSprite, 14);
                _loc_4.value = 0;
                this._vcAttributeValueText.push(_loc_4);
                pushUIToDisposeVec(_loc_4);
                _loc_3 = UIFactory.gTextField("", 80 + _loc_7 % 2 * 130, 8.5 * (_loc_7 - _loc_7 % 2) + 18, 60, 20, this._attrSprite, GlobalStyle.textFormatItemGreen.left());
                this._vcAttributeAddValueText.push(_loc_3);
                pushUIToDisposeVec(_loc_3);
                _loc_5 = UIFactory.gBitmap(ImagesConst.ascendingSortBtn_upSkin, 65 + _loc_7 % 2 * 130, 8.5 * (_loc_7 - _loc_7 % 2) + 22, this._attrSprite);
                _loc_5.visible = false;
                this._vcAttributeAddValueBitMap.push(_loc_5);
                pushUIToDisposeVec(_loc_5);
                _loc_7++;
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            this._attrSprite.name = "";
            this._attrSprite.dispose(param1);
            this._attrSprite = null;
            this._upgradeBtn.name = "";
            this._upgradeBtn.dispose(param1);
            this._upgradeBtn = null;
            this._soulPanel.dispose(param1);
            this._soulPanel = null;
            this._soulBg.dispose(param1);
            this._soulBg = null;
            this._comBat.dispose(param1);
            this._comBat = null;
            this._name.dispose(param1);
            this._name = null;
            this._consumeBox.dispose(param1);
            this._consumeBox = null;
            this._consumeBox2.dispose(param1);
            this._consumeBox2 = null;
            this._addCombat.dispose(param1);
            this._addCombat = null;
            this._addCombatIcon.dispose(param1);
            this._addCombatIcon = null;
            this._level.dispose(param1);
            this._level = null;
            this._isOver = false;
            this._vcAttributeName2.length = 0;
            this._vcAttributeValueText.length = 0;
            this._vcAttributeAddValueText.length = 0;
            this._vcAttributeAddValueBitMap.length = 0;
            this._currentWizardData = null;
            super.disposeImpl(param1);
            return;
        }// end function

        private function upgradeHandler(event:MouseEvent) : void
        {
            if (this._currentWizardData == null)
            {
                return;
            }
            if (!this._currentWizardData.isHasWizard)
            {
                MsgManager.showRollTipsMsg(Language.getString(30411));
                return;
            }
            if (event.target == this._upgradeBtn)
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.WizardUpgradeSoul, this._currentWizardData));
            }
            return;
        }// end function

        private function showAttrUp(event:MouseEvent = null) : void
        {
            if (event)
            {
                this._isOver = true;
            }
            if (!this._isOver || this._currentWizardData == null)
            {
                return;
            }
            var _loc_2:* = WizardConfig.instance.vcAttributeName;
            var _loc_3:* = _loc_2.length;
            var _loc_4:int = 0;
            var _loc_5:int = 0;
            while (_loc_5 < _loc_3)
            {
                
                this._vcAttributeAddValueText[_loc_5].text = this._currentWizardData.tSprite[_loc_2[_loc_5]];
                this._vcAttributeAddValueBitMap[_loc_5].visible = true;
                _loc_5++;
            }
            var _loc_6:* = WizardUtil.getNextAddWizadCombatByCode(this._currentWizardData.code);
            this._addCombat.text = _loc_6 > 0 ? (_loc_6.toString()) : ("");
            this._addCombatIcon.visible = _loc_6 > 0 ? (true) : (false);
            return;
        }// end function

        private function hidAttrUp(event:MouseEvent = null) : void
        {
            if (event)
            {
                this._isOver = false;
            }
            var _loc_2:* = this._vcAttributeAddValueText.length;
            var _loc_3:int = 0;
            while (_loc_3 < _loc_2)
            {
                
                this._vcAttributeAddValueText[_loc_3].text = "";
                this._vcAttributeAddValueBitMap[_loc_3].visible = false;
                _loc_3++;
            }
            this._addCombat.text = "";
            this._addCombatIcon.visible = false;
            return;
        }// end function

        private function visibleInitialization() : void
        {
            this._upgradeBtn.filterEnabled = true;
            this._upgradeBtn.visible = true;
            this._consumeBox.visible = true;
            this._consumeBox2.visible = true;
            return;
        }// end function

        public function set data(param1:WizardData) : void
        {
            this._currentWizardData = param1;
            this._name.imgUrl = "Sprite" + this._currentWizardData.code + "_overSkin";
            return;
        }// end function

        public function refreshSprite() : void
        {
            this.visibleInitialization();
            this._soulPanel.setWizardInfo(this._currentWizardData);
            if (this._currentWizardData.isHasWizard)
            {
                this._comBat.value = this._currentWizardData.spriteInfo.combat;
                this._level.text = "[" + this._currentWizardData.spriteInfo.SpriteLevel + Language.getString(35614);
                if (this._currentWizardData.spriteInfo.SpriteLevel >= WizardUtil.maxLevel)
                {
                    this._upgradeBtn.enabled = false;
                    this._upgradeBtn.filters = [FilterConst.colorFilter2];
                    this._consumeBox.visible = false;
                    this._consumeBox2.visible = false;
                }
                else
                {
                    this._consumeBox.resetValue("1", this._currentWizardData.tSprite.coin);
                    this._consumeBox.resetValue("2", this._currentWizardData.tSprite.vitalenergy);
                }
            }
            else
            {
                this._upgradeBtn.visible = false;
                this._consumeBox.visible = false;
                this._consumeBox2.visible = false;
                this._level.text = "";
                this._comBat.value = 0;
            }
            return;
        }// end function

        public function updateMoney() : void
        {
            return;
        }// end function

        public function updateCombat() : void
        {
            this._comBat.addToValue(this._currentWizardData.isHasWizard ? (WizardUtil.getWizardCombatByCode(this._currentWizardData.code)) : (0));
            return;
        }// end function

        public function updateAttrData() : void
        {
            var value:int;
            var txt:GTextFiled;
            var removeTxt:Function;
            var curAttrValue:int;
            removeTxt = function (param1:GTextFiled) : void
            {
                param1.dispose(true);
                return;
            }// end function
            ;
            this.updateCombat();
            var vcAttributeName:* = WizardConfig.instance.vcAttributeName;
            var attrNum:* = vcAttributeName.length;
            var i:int;
            while (i < attrNum)
            {
                
                if (this._currentWizardData.isHasWizard)
                {
                    curAttrValue = WizardUtil.getWizardAttrValueByCodeAndName(this._currentWizardData.tSprite.code, vcAttributeName[i]);
                    if (this._vcAttributeValueText[i].text == "" || int(this._vcAttributeValueText[i].text) == curAttrValue)
                    {
                        EffectManager.glowFilterUnReg(this._vcAttributeValueText[i]);
                    }
                    else if (int(this._vcAttributeValueText[i].text) < curAttrValue)
                    {
                        value = curAttrValue - int(this._vcAttributeValueText[i].text);
                        EffectManager.glowFilterReg(this._vcAttributeValueText[i], null, 1, 10, 0, 3);
                        txt = UIFactory.gTextField("+" + value, this._vcAttributeValueText[i].x + 50, this._vcAttributeValueText[i].y - 3, 100, 20, this._attrSprite);
                        TweenMax.to(txt, 2, {alpha:0, y:txt.y - 25, ease:Quint.easeOut, onComplete:removeTxt, onCompleteParams:[txt]});
                    }
                    this._vcAttributeValueText[i].text = curAttrValue.toString();
                }
                else
                {
                    this._vcAttributeValueText[i].text = "0";
                    EffectManager.glowFilterUnReg(this._vcAttributeValueText[i]);
                }
                i = (i + 1);
            }
            this.showAttrUp();
            return;
        }// end function

        public function setAttrData() : void
        {
            var _loc_3:int = 0;
            var _loc_1:* = WizardConfig.instance.vcAttributeName;
            var _loc_2:* = _loc_1.length;
            var _loc_4:int = 0;
            while (_loc_4 < _loc_2)
            {
                
                _loc_3 = WizardUtil.getWizardAttrValueByCodeAndName(this._currentWizardData.tSprite.code, _loc_1[_loc_4]);
                EffectManager.glowFilterUnReg(this._vcAttributeValueText[_loc_4]);
                if (this._currentWizardData.isHasWizard)
                {
                    this._vcAttributeValueText[_loc_4].text = _loc_3.toString();
                }
                else
                {
                    this._vcAttributeValueText[_loc_4].text = "0";
                }
                _loc_4++;
            }
            return;
        }// end function

        public function showFilter(param1:int) : void
        {
            switch(param1)
            {
                case WizardNewInfoPanel.upgradeBtn:
                {
                    EffectManager.glowFilterReg(this._upgradeBtn, null, 1, 10, 0, 6);
                    break;
                }
                case WizardNewInfoPanel.consumeBox2:
                {
                    EffectManager.glowFilterReg(this._consumeBox2, [FilterConst.redTipsFilter], 1, 10, 0, 3);
                    break;
                }
                default:
                {
                    break;
                }
            }
            return;
        }// end function

    }
}
